<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/30 0030
 * Time: 下午 8:37
 */

namespace app\index\controller;


use think\Db;

class Contact extends Base
{
    protected $beforeActionList=['category'];
    public function index(){
        if ($this->request->isPost()){
            $post = $this->request->post('','','htmlspecialchars');
            if (empty($post['name'])){
                return ['code'=>'name'];
            }elseif (empty($post['tel'])){
                return ['code'=>'tel'];
            }elseif (empty($post['mail'])){
                return ['code'=>'mail'];
            }elseif (empty($post['content'])){
                return ['code'=>'content'];
            }elseif (empty(cache($this->request->ip()))){
                if (Db::name('msg')->insert([
                    'create_at'=>date('Y-m-d H:i:s'),
                    'content'=>json_encode($post,320),
                    'type'=>1
                ])){
                    cache($this->request->ip(),'123',300);
                }
                return ['code'=>1];
            }else{
                return ['code'=>'busy'];
            }
        }
        $this->assign([
            'pcate'=>['name'=>'联系我们','id'=>''],
            'cur'=>['name'=>'联系我们','id'=>''],
        ]);
        return view();
    }
}